﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using PowerPoint;
using System.Windows.Forms;
namespace PPTtoPicture
{
    class WPSApi
    {
        //public  delegate void Rate_Of_Progress(System.Windows.Forms.ProgressBar probar);
        public static Bitmap PPT_To_Bitmap(string file,string filepath , System.Windows.Forms.ProgressBar probar)
        {
            
            PowerPoint.ApplicationClass pptappclass = new ApplicationClass();
            var presentations = pptappclass.Presentations ;
            //var presentation = pptappclass.ActivePresentation; ;
            //var app = presentations.Application;
            PowerPoint.Presentation present = pptappclass.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            int pageCount = present.Slides.Count;
            int pageNum = 0;
            //Rate_Of_Progress rateprocess = (System.Windows.Forms.ProgressBar bar) => {
            //    bar.Maximum = pageCount;
            //};
            //rateprocess.Invoke(probar);
            probar.Maximum = pageCount;
            foreach (PowerPoint.Slide pptSlide in present.Slides)
            {
                pptSlide.Export(string.Format("{0}\\PPT_{1}.jpg", filepath, pageNum.ToString("D2")), "JPG", 1920, 1080);
                pageNum++;
                System.Threading.Thread.Sleep(100);
                probar.Value = pageNum;
            }
            Bitmap pic = new Bitmap(100, 100);
            return pic;
        }
       
    }
}
